<?php include_once("header.html"); ?>

<head>
    <link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>system/application/styles/admin_view_select.css" />
	<meta http-equiv="content-type" content="text/html;charset=utf-8" />
	<meta name="generator" content="Geany 0.16" />
    <script type="text/javascript">
        function setId()
        {
            if (opener && !opener.closed && opener.setField)
            {
                var id;
                var name;
                for (i = 0; i < document.select.id.length; i++)
                {
                    if (document.select.id[i].checked == true)
                    {
                        id = document.select.id[i].value;
                        name = document.getElementById('myTable').rows[i+1].cells[1].innerHTML; // +1 bo trzeba liczyć header
                        break;
                    }
                }
                opener.setField(field, idfield, name, id);
            }
            window.close();
        }
        
        function setIds()    // dla wielokrotnego wyboru
        {
            if (opener && !opener.closed && opener.setField)
            {
                var id = new String();
                var name = new String();
                for (i = 0; i < document.select.id.length; i++)
                {
                    if (document.select.id[i].checked == true)
                    {
                        id = id.concat(document.select.id[i].value, ';');
                        
                        // +1 bo trzeba liczyć header
                        name = name.concat(document.getElementById('myTable').rows[i+1].cells[1].innerHTML,'\n');
                    }
                }
                opener.setField(field, idfield, name, id);
            }
            window.close();
        }

    </script> 
</head>

<body>
<div id="space">
    <?php
    echo form_open('admin/content/select_update/', array('name' => 'select'));
  
    $this->table->set_heading($heading);       
    $tmpl = array ('table_open' => '<table border="1" cellpadding="4" cellspacing="0" id="myTable">');
    $this->table->set_template($tmpl); 
    
    foreach($query->result_array() as $row):
        $row[] = $multi ? form_checkbox('id', $row['id'], FALSE) : form_radio('id', $row['id'], FALSE);
        $this->table->add_row($row);
    endforeach;
    
    echo $this->table->generate();
    ?><div id="buttons"><?php
    echo form_button('cancel', 'Anuluj', 'onClick="window.close()"');
    echo form_button('ok', 'Wybierz', $multi ? 'onClick="setIds()"' : 'onClick="setId()"');?></div><?php
    echo form_close();
    
    echo $this->pagination->create_links();
    ?>
</div>    
</body>
